import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from math import factorial
import sympy as sp
sp.init_printing()
sp.var("x")
x
f = sp.sqrt(x-10)
n = 3
x0 = 12
tn = 0
for i in range(n+1):
tn += f.diff(x, i).subs(x, x0)/factorial(i) * (x-x0)**i
tn
The error of the Taylor approximation of degree 3 about x0 = 12 when h=0.5 is (that is, x = 12.5):
f.subs(x, 12.5)
t.subs(x, 12.5).evalf()
error1 = f.subs(x, 12.5) - t.subs(x, 12.5).evalf()
abs(error1)
Now predict the error at $12.25$:
and the actual error is:
error2 = f.subs(x, 12.25) - t.subs(x, 12.25).evalf()
abs(error2)